package com.gdpu.project.action.achievementAnalyse;

import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.gdpu.page.vo.ScoreIndex;
import com.gdpu.project.dao.*;
import com.gdpu.project.service.ChengGuoService;
import com.gdpu.project.service.ScoreCheck;
import com.gdpu.project.util.DateUtil;
import com.gdpu.project.vo.CgConference;
import com.gdpu.project.vo.Teacher;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class researchPoint extends  HibernateDaoSupport implements Action{
	private Date startTime;
	private Date endTime;
	private String teacCoOrCata;
	private CgConferenceDao cgconference;
	private CgInnovateDao cginnovate;
	private CgPatentDao cgpatent;
	private CgProjectDao cgproject;
	private CgThesisDao cgthesis;
	private CgTreatiseDao cgtreatise;
	private ChengGuoService chengguoService;
	private ScoreCheck scorecheck;

	
	public ScoreCheck getScorecheck() {
		return scorecheck;
	}


	public void setScorecheck(ScoreCheck scorecheck) {
		this.scorecheck = scorecheck;
	}


	public CgConferenceDao getCgconference() {
		return cgconference;
	}


	public void setCgconference(CgConferenceDao cgconference) {
		this.cgconference = cgconference;
	}


	public CgInnovateDao getCginnovate() {
		return cginnovate;
	}


	public void setCginnovate(CgInnovateDao cginnovate) {
		this.cginnovate = cginnovate;
	}


	public CgPatentDao getCgpatent() {
		return cgpatent;
	}


	public void setCgpatent(CgPatentDao cgpatent) {
		this.cgpatent = cgpatent;
	}


	public CgProjectDao getCgproject() {
		return cgproject;
	}


	public void setCgproject(CgProjectDao cgproject) {
		this.cgproject = cgproject;
	}


	public CgThesisDao getCgthesis() {
		return cgthesis;
	}


	public void setCgthesis(CgThesisDao cgthesis) {
		this.cgthesis = cgthesis;
	}


	public CgTreatiseDao getCgtreatise() {
		return cgtreatise;
	}


	public void setCgtreatise(CgTreatiseDao cgtreatise) {
		this.cgtreatise = cgtreatise;
	}
	
	public void setTeacCoOrCata(String teacCoOrCata) {
		this.teacCoOrCata = teacCoOrCata;
	}



	public ChengGuoService getChengguoService() {
		return chengguoService;
	}


	public void setChengguoService(ChengGuoService chengguoService) {
		this.chengguoService = chengguoService;
	}


	public String getTeacCoOrCata() {
		return teacCoOrCata;
	}


	public Date getStartTime() {
		return startTime;
	}


	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}


	public Date getEndTime() {
		return endTime;
	}


	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}


	@SuppressWarnings("unchecked")
	public String execute() throws Exception {
		HttpServletRequest request=ServletActionContext.getRequest();	
		request.setCharacterEncoding("UTF-8");
		String hql = null;
		Pattern pattern=Pattern.compile("\\d{6}");
		if(pattern.matcher(teacCoOrCata.trim()).find()){
			hql="from Teacher as t where t.teacherId = ?";
		}else{
			hql="from Teacher as t where t.cataloge = ?";
		}
			
		Object[] args={teacCoOrCata};
		List<ScoreIndex> scoreindex = new LinkedList<ScoreIndex>();
		/*if(teacCoOrCata.indexOf("ϵ")!=-1){
			hql="from Teacher as t where t.cataloge = ?";
		}else{
			hql="from Teacher as t where t.teacherId = ?";
		}*/
		List<Teacher> teacher=(List<Teacher>)getHibernateTemplate().find(hql, args);
		scoreindex = scorecheck.search(teacher,startTime,endTime);
		request.setAttribute("scorelist", scoreindex);
		String startString="  ";
		if(startTime!=null){
			startString=DateUtil.dateToString(startTime);
		}
		String endString=" 今";
		if(endTime!=null){
			endString=DateUtil.dateToString(endTime);
		}		
		request.setAttribute("timeScope", startString+"至"+endString);
		return "research";
	}
	
}
